<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .input-wrap {
      width: 240px;
      height: 32px;
      border: 1px solid;
      border-radius: 2px;
    }
    input {
      border: 0;
      width: 200px;
      height: 30px;
      outline: none;
    }
  </style>
</head>
<body>
  <div id="app">
    <h2>动态组件</h2>
    <button @click="componentName = 'Tab1'">111</button>
    <button @click="componentName = 'Tab2'">222</button>
    <button @click="componentName = 'Tab3'">333</button>
    <button @click="componentName = 'Tab4'">444</button>

    <!-- <tab1 v-if="type === 1"></tab1>
    <tab2 v-if="type === 2"></tab2>
    <tab3 v-if="type === 3"></tab3>
    <tab4 v-if="type === 4"></tab4> -->


    <!-- 动态组件就是来优化上面这种方式的 -->
    <!-- 必须要配合一个is属性, 写字符串，字符串的是组件的名字 -->
    <!-- 只要组件的名字和is属性相同，那么component组件就会自动渲染成这个名字的组件 -->
    <component :is="componentName"></component>
  </div>

  <script src="../vue3.js"></script>
  <script>
    const {createApp} = Vue;

    const Tab1 = {
      template: `
        <div>这是tab1组件</div>
      `
    }
    const Tab2 = {
      template: `
        <div>这是tab2组件</div>
      `
    }
    const Tab3 = {
      template: `
        <div>这是tab3组件</div>
      `
    }
    const Tab4 = {
      template: `
        <div>这是tab4组件</div>
      `
    }

    const app = createApp({
      data() {
        return {
          // type: 1
          componentName: "Tab1"
        }
      },
      components: {
        Tab1,
        Tab2,
        Tab3,
        Tab4
      }
    });

    app.mount("#app");
  </script>
</body>
</html>